package com.mongodb;

import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

public class TestConn {
    public static void main(String[] args){

        MongoClient client = new MongoClient("192.168.196.130");

        MongoDatabase spitdb = client.getDatabase("spit");
        //得到集合
        MongoCollection<Document> spit = spitdb.getCollection("spit");
        FindIterable<Document> documents = spit.find();

        for (Document d:documents) {
            System.out.println("内容:"+d.getString("content"));
            System.out.println("用户id"+d.getString("userid"));
            System.out.println("浏览量："+d.getInteger("visits"));

        }
        //关闭连接
        client.close();
    }
}
